﻿package org.hsl.avm2.translation.http;
/**
 * A HTTP status. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more information.
 */
class HTTPStatus {
	/**
	 * The class of the HTTP status. The class is determined by the first digit of the HTTP status code.
	 */
	public var statusClass(getStatusClass, null):HTTPStatusClass;
	/**
	 * The status code of the HTTP status.
	 */
	public var statusCode(default, null):Int;
	/**
	 * Creates a new HTTP status.
	 */
	public function new(statusCode:Int):Void {
		this.statusCode = statusCode;
	}
	// We're using a getter here, because we expect this property will not be accessed often.
	private inline function getStatusClass():HTTPStatusClass {
		switch (Math.floor(statusCode * .01)) {
			case 1:
			return HTTPStatusClass.informational;
			case 2:
			return HTTPStatusClass.successful;
			case 3:
			return HTTPStatusClass.redirection;
			case 4:
			return HTTPStatusClass.clientError;
			case 5:
			return HTTPStatusClass.serverError;
			default:
			return HTTPStatusClass.unknown;
		}
	}
	private function toString():String {
		return "[HTTPStatus statusClass=\"" + statusClass + "\" statusCode=" + statusCode + "]";
	}
}
/**
 * The class of a HTTP status. The class is determined by the first digit of the HTTP status code. See
 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more information.
 */
enum HTTPStatusClass {
	/**
	 * This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and
	 * is terminated by an empty line.
	 */
	informational;
	/**
	 * This class of status code indicates that the client's request was successfully received, understood, and accepted.
	 */
	successful;
	/**
	 * This class of status code indicates that further action needs to be taken by the user agent in order to fulfill the
	 * request.
	 */
	redirection;
	/**
	 * This class of status code is intended for cases in which the client seems to have erred.
	 */
	clientError;
	/**
	 * This class of status code indicates that the server is aware that it has erred or is incapable of performing the request.
	 */
	serverError;
	/**
	 * This class of status code is preserved for unknown status codes.
	 */
	unknown;
}